////////////////////////////////////////////////////////////////////////////////
//
//	This file is part of Woozox, see <http://code.google.com/p/woozox/>.
//
//	Copyright 2008-2009 Florian David
//
//	Woozoo is free software: you can redistribute it and/or modify
//	it under the terms of the GNU Lesser General Public License as 
//	published by the Free Software Foundation, either version 3 of 
//	the License, or (at your option) any later version.
//
//	Woozoo is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU Lesser General Public 
//	License along with Woozoo. If not, see <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
package org.woozoo.xhtml.core.base
{
	/**
	 * A category represents a document that can have sub categories or / and documents.
	 * <p>Most of the time a category reprensent a menu item.</p>
	 * */
	public class Category
	{
		public static const DEFAULT_CATEGORY_NAME : String = 'defaultCategory';
		
		private var __parent : Category;
		private var __children : Array = [];
		private var __subCategories : Array = [];
		private var __documents : Array = [];
		
		private var __document : Document;
		private var __name : String;
		
		/**
		 * Constructor
		 * */
		public function Category(name:String)
		{
			__name = name;
		}
		
		/**
		 * The name of the category
		 * */
		public function get name() : String {
			return __name;
		}
		
		/**
		 * The document related to this category
		 * */
		public function get document() : Document {
			return __document;
		}
		public function set document(value : Document) : void {
			__document = value;
		}
		
		/**
		 * The list of children (subCategories + documents) of this category.
		 * 
		 * @return The children
		 * */
		public function get children() : Array {
			return __children;
		}
		
		/**
		 * The parent of this category (null if no parent) 
		 * */
		public function get parent() : Category {
			return __parent;
		}
		public function set parent(value : Category) : void {
			__parent = value;
		}
		
		/**
		 * Add a list of subCategories to this category.
		 * 
		 * @param list A list of Category
		 * */
		public function addSubCategories(list : Array) : void {
			__subCategories = __subCategories.concat(list);
			__children = __children.concat(list);
		}
		
		/**
		 * Add a subCategory to this category
		 * 
		 * @param category The sub category
		 * */
		public function addSubCategory(category : Category) : Category {
			if (__subCategories.indexOf(category) == -1) {
				__subCategories.push(category);
			}
			if (__children.indexOf(category) == -1) {
				__children.push(category);
			}
			return category;
		} 
		
		public function get subCategories() : Array {
			return __subCategories;
		} 
		
		public function addDocument(document : Document) : Document {
			if (__documents.indexOf(document) == -1) {
				__documents.push(document);
			}
			if (__children.indexOf(document) == -1) {
				__children.push(document);
			}
			return document;
		}
		
		public function get documents() : Array {
			return __documents;
		}
	}
}